<template>
  <div>
<!--注册页面-->
    <div>
      <el-form :rules="rules"  v-loading="loading" ref="formRegister" :model="Register" class="loginCont">
        <h3 class="lofinTitle">注册页面</h3>
        <el-form-item prop="username">
          <el-input type="text" prefix-icon="el-icon-user-solid" v-model="Register.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" prefix-icon="el-icon-lock" v-model="Register.password" placeholder="请输入密码" show-password></el-input>
        </el-form-item>
        <el-form-item prop="againpassword">
          <el-input type="password" prefix-icon="el-icon-lock" v-model="Register.againpassword"  placeholder="确认密码" show-password></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-input type="text" v-model="Register.code" placeholder="请输入验证码" style="width: 250px; margin-right: 5px"></el-input>
        </el-form-item>
        <img :src="captchaUrl">
        <el-button type="primary" style="width: 100%" @click="registersubmit">确认</el-button>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "Register",
  data() {
    return {
      captchaUrl:'',
      Register:{
        username:"",
        password:'',
        againpassword:'',
        code:''
      },
      rules: {
        username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
        password: [{required: true, message: '请输入密码', trigger: 'blur'}],
        againpassword: [{required: true, message: '请输入确认密码', trigger: 'blur'}],
        code: [{required: true, message: '请输入验证码', trigger: 'blur'}],
      },
      loading:false,
    }
  },
  methods :{
    registersubmit() {


      this.$refs.formRegister.validate((valid) => {
        if (valid) {
          if (this.Register.password != this.Register.againpassword){
            this.$message({showClose: true, message: '两次密码不一致', type: 'warning'});
            return;
          }
          this.$message({message: '注册成功', type: 'success'});
          this.$router.replace('/');//replace 可禁止返回上个页面
        } else {
          console.log('error submit!!');
          this.$message.error('请输入所有字段');
          return false;
        }
      });


    }
  }
}
</script>

<style scoped>
.loginCont{
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 15px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
.lofinTitle{
  margin: 8px auto 40px auto;
  text-align: center;
}
.register{
  margin-top: 25px;
  font-size: 14px;
  text-align: center;
}

</style>
